package dhm.com.dhmshop.adapter.mine;

import android.content.Context;
import android.content.Intent;
import android.support.annotation.NonNull;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.facebook.drawee.view.SimpleDraweeView;

import java.util.ArrayList;
import java.util.List;

import dhm.com.dhmshop.R;
import dhm.com.dhmshop.adapter.order.ChildOrderAdapter;
import dhm.com.dhmshop.base.netWork.Constant;
import dhm.com.dhmshop.entity.GetAllOrder;
import dhm.com.dhmshop.entity.MyShops;
import dhm.com.dhmshop.entity.Myorder;
import dhm.com.dhmshop.entity.ShopCarBean;
import dhm.com.dhmshop.framework.module.commodity.activity.CommodityDetailsActivity;
import dhm.com.dhmshop.updata.activity.GoodsfunctionActivity;
import dhm.com.dhmshop.updata.activity.SaleserviceActivity;
import dhm.com.dhmshop.utils.CustomJiaJian;
import dhm.com.dhmshop.utils.SpUtils;
import dhm.com.dhmshop.view.home.OrderdetailActivity;
import dhm.com.dhmshop.view.mine.myshop.ShoporderActivity;
import dhm.com.dhmshop.view.mine.myshop.ShoporderdActivity;
import dhm.com.dhmshop.view.mine.order.ShowevaluateActivity;

/**
 * Created by admin
 * 2019/4/29
 * 所有订单适配器
 */
public class MyOrderAdapter extends RecyclerView.Adapter<MyOrderAdapter.ViewHolder> {

    private List<GetAllOrder.DataBean> shopList;
    private Context context;
    //        type 0:全部 1:代付款 2.待发货 3.待收货   4.待评价
    private String type;


    public MyOrderAdapter(Context context,String type) {
        this.shopList = new ArrayList<>();
        this.context = context;
        this.type=type;
    }


    public void setShopList(List<GetAllOrder.DataBean> shopList) {
        this.shopList = shopList;
        notifyDataSetChanged();
    }

    @NonNull
    @Override
    public ViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) {
        ViewHolder viewHolder;
        View view= LayoutInflater.from(context).inflate(R.layout.item_myorder, viewGroup,false);
        viewHolder=new ViewHolder(view);
        return viewHolder;
    }

    @Override
    public void onBindViewHolder(@NonNull ViewHolder viewHolder, final int i) {
        switch (type){
            case "0":
                //全部
                viewHolder.tofu.setVisibility(View.GONE);
                viewHolder.toshou.setVisibility(View.GONE);
                viewHolder.tofa.setVisibility(View.GONE);
                viewHolder.toping.setVisibility(View.GONE);
                break;
            case "1":
                //代付款
                viewHolder.tofu.setVisibility(View.VISIBLE);
                viewHolder.toshou.setVisibility(View.GONE);
                viewHolder.tofa.setVisibility(View.GONE);
                viewHolder.toping.setVisibility(View.GONE);
                viewHolder.xiu.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View view) {
//                        取消订单
                        onClick.item(i);
                    }
                });
                viewHolder.topay.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View view) {

                        onIntentClick.item(i);

                    }
                });

                break;
            case "2":
                //待发货
                viewHolder.tofu.setVisibility(View.GONE);
                viewHolder.toshou.setVisibility(View.GONE);
                viewHolder.tofa.setVisibility(View.VISIBLE);
                viewHolder.toping.setVisibility(View.GONE);
                viewHolder.cui.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View view) {
//                        提醒发货
                        onClick.item(i);
                    }
                });
                viewHolder.tousu.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View view) {
//                        投诉
//                        onIntentClick.item(i);
                        Intent intent=new Intent(context, GoodsfunctionActivity.class);
                        intent.putExtra("bean",shopList.get(i));
                        context.startActivity(intent);
                    }
                });

                viewHolder.buys.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View view) {
//                        取消订单
                        onshopClick.item(i);

                    }
                });
                break;
            case "3":
                //待收货
                viewHolder.tofu.setVisibility(View.GONE);
                viewHolder.toshou.setVisibility(View.VISIBLE);
                viewHolder.tofa.setVisibility(View.GONE);
                viewHolder.toping.setVisibility(View.GONE);
                viewHolder.cha.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View view) {
//                        投诉
                        Intent intent=new Intent(context, GoodsfunctionActivity.class);
                        intent.putExtra("bean",shopList.get(i));
                        context.startActivity(intent);
                    }
                });
                viewHolder.sure.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View view) {
//                        确认收货
                        onshopClick.item(i);
                    }
                });
                viewHolder.ju.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View view) {
//                        拒收
                        onIntentClick.item(i);
                    }
                });


                break;
            case "4":
                //待评价
                viewHolder.tofu.setVisibility(View.GONE);
                viewHolder.toshou.setVisibility(View.GONE);
                viewHolder.tofa.setVisibility(View.GONE);
                viewHolder.toping.setVisibility(View.VISIBLE);
                viewHolder.liu.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View view) {
//                        申请售后
                        Intent intent=new Intent(context, SaleserviceActivity.class);
                        intent.putExtra("bean",shopList.get(i));
                        context.startActivity(intent);
                    }
                });
                viewHolder.ts.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View view) {
//                        投诉
                        Intent intent=new Intent(context, GoodsfunctionActivity.class);
                        intent.putExtra("bean",shopList.get(i));
                        context.startActivity(intent);
                    }
                });
                viewHolder.ping.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View view) {
//
                        Intent intent = new Intent(context, ShowevaluateActivity.class);
                        intent.putExtra("bean",shopList.get(i));
                        context.startActivity(intent);
                    }
                });

                break;
            case "5":
//                已完成
                viewHolder.tofu.setVisibility(View.GONE);
                viewHolder.toshou.setVisibility(View.GONE);
                viewHolder.tofa.setVisibility(View.GONE);
                viewHolder.toping.setVisibility(View.VISIBLE);
                viewHolder.liu.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View view) {
//                        申请售后
                        Intent intent=new Intent(context, SaleserviceActivity.class);
                        intent.putExtra("bean",shopList.get(i));
                        context.startActivity(intent);
                    }
                });
                viewHolder.ts.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View view) {
//                        投诉
                        Intent intent=new Intent(context, GoodsfunctionActivity.class);
                        intent.putExtra("bean",shopList.get(i));
                        context.startActivity(intent);
                    }
                });
                viewHolder.ping.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View view) {
//                         评价
                        Intent intent = new Intent(context, ShowevaluateActivity.class);
                        intent.putExtra("bean",shopList.get(i));
                        context.startActivity(intent);
                    }
                });
                break;
            case "6":
//                取消拒收
                viewHolder.tofu.setVisibility(View.GONE);
                viewHolder.toshou.setVisibility(View.GONE);
                viewHolder.tofa.setVisibility(View.GONE);
                viewHolder.toping.setVisibility(View.GONE);
                break;
                default:
        }

        viewHolder.nameshop.setText(shopList.get(i).getShopName());

        LinearLayoutManager manager=new LinearLayoutManager(context);
        manager.setOrientation(LinearLayoutManager.VERTICAL);

        ChildOrderAdapter childOrderAdapter=new ChildOrderAdapter(context);


        viewHolder.recy.setLayoutManager(manager);
        viewHolder.recy.setAdapter(childOrderAdapter);

//        if (shopList.get(i).getGoods_arr()==null){
//            Myorder.DataBean.GoodsArrBean goodsArrBean=new Myorder.DataBean.GoodsArrBean();
//            goodsArrBean.setCount(shopList.get(i).getCount());
//            goodsArrBean.setDesc(shopList.get(i).getDesc());
//            goodsArrBean.setGoods_id(shopList.get(i).getGoods_id());
//            goodsArrBean.setGoods_img(shopList.get(i).getGoods_img());
//            goodsArrBean.setGoods_name(shopList.get(i).getGoods_name());
//            goodsArrBean.setGoods_param(shopList.get(i).getGoods_param());
//            goodsArrBean.setPrice(shopList.get(i).getPrice());
//            List<Myorder.DataBean.GoodsArrBean> list=new ArrayList<>();
//            list.add(goodsArrBean);
//            shopList.get(i).setGoods_arr(list);
//        }
        childOrderAdapter.setImageList(shopList.get(i).getList());

        viewHolder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent=new Intent(context, ShoporderdActivity.class);
                intent.putExtra("order_id",shopList.get(i).getOrderId()+"");
                intent.putExtra("uid", SpUtils.getString(context,"uid"));
                context.startActivity(intent);
            }
        });

    }

    @Override
    public int getItemCount() {
        return shopList.size();
    }

    class ViewHolder extends RecyclerView.ViewHolder {

        public LinearLayout shops;
        public CheckBox check;
        public CheckBox nameshop;
        public RecyclerView recy;

        RelativeLayout toshou;
        RelativeLayout tofa;
        RelativeLayout tofu;
        RelativeLayout toping;
        TextView cha;
        TextView sure;
        TextView ju;
        TextView cui;
        TextView tousu;
        TextView buys;
        TextView xiu;
        TextView topay;
        TextView liu;
        TextView ts;
        TextView ping;

        public ViewHolder(@NonNull View itemView) {
            super(itemView);
            shops=itemView.findViewById(R.id.shops);
            check=itemView.findViewById(R.id.check);
            toshou=itemView.findViewById(R.id.toshou);
            cha=itemView.findViewById(R.id.cha);
            sure=itemView.findViewById(R.id.sure);
            ju=itemView.findViewById(R.id.ju);
            tofa=itemView.findViewById(R.id.tofa);
            cui=itemView.findViewById(R.id.cui);
            tousu=itemView.findViewById(R.id.tousu);
            buys=itemView.findViewById(R.id.buys);
            tofu=itemView.findViewById(R.id.tofu);
            xiu=itemView.findViewById(R.id.xiu);
            topay=itemView.findViewById(R.id.topay);
            toping=itemView.findViewById(R.id.toping);
            liu=itemView.findViewById(R.id.liu);
            ping=itemView.findViewById(R.id.ping);
            nameshop=itemView.findViewById(R.id.nameshop);
            recy=itemView.findViewById(R.id.recy);
            ts=itemView.findViewById(R.id.ts);
        }
    }

    private OnClick onClick;
    public void setdeleteClick(OnClick onClick) {
        this.onClick = onClick;
    }
    public interface OnClick{
        void item(int posttion);
    }

    private OnIntentClick onIntentClick;
    public void setaddClick(OnIntentClick onClick) {
        this.onIntentClick = onClick;
    }
    public interface OnIntentClick{
        void item(int posttion);
    }

    private OnShopClick onshopClick;
    public void setaddClick(OnShopClick onClick) {
        this.onshopClick= onClick;
    }
    public interface OnShopClick{
        void item(int posttion);
    }


    private OnShowClick onshowClick;
    public void setaddClick(OnShowClick onClick) {
        this.onshowClick= onClick;
    }
    public interface OnShowClick{
        void item(int posttion,View view);
    }



}

